package com.tianluo.tianluobookstore.enums;

public enum PaymentStatus {
    NOT_PAID("NOT_PAID", "未支付"),
    PAID("PAID", "已支付");

    private final String code;
    private final String description;

    PaymentStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取对应的枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例，如果不存在则返回null
     */
    public static PaymentStatus fromCode(String code) {
        for (PaymentStatus status : PaymentStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
